package com.example.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.pojo.SysUser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.vo.UserVo;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 用户表 Mapper 接口
 * </p>
 *
 * @author lyj
 * @since 2023-02-15
 */
public interface SysUserMapper extends BaseMapper<SysUser> {

    @Select("select so.name officeName,su.*\n" +
            "from sys_user su \n" +
            "left join sys_office so on su.office_id=so.id ${ew.customSqlSegment}")
    Page<UserVo> queryUserVoByCondition(Page<UserVo> page, QueryWrapper<UserVo> ew);

    @Select("select su.*\n" +
            "from sys_user su \n" +
            "left join sys_user_role sur on su.id=sur.user_id\n" +
            "where su.del_flag=0\n" +
            "and sur.del_flag=0\n" +
            "and sur.role_id=#{id}")
    List<SysUser> queryByRoleId(long id);

    @Select("select su.*\n" +
            "from sys_office so \n" +
            "left join sys_user su on su.office_id=so.id\n" +
            "where so.del_flag=0\n" +
            "and su.del_flag=0\n" +
            "and so.roles like CONCAT('%',#{s},'%')")
    List<SysUser> queryByQualification(String s);
}
